Skip to content

fix(openai): omit temperature when no custom value is set (#242)#247

Merged
edelauna merged 1 commit into
Zoo-Code-Org:mainfrom
proyectoauraorg:fix/242-omit-temperature-when-unset
Jun 2, 2026
Merged

fix(openai): omit temperature when no custom value is set (#242)#247
edelauna merged 1 commit into
Zoo-Code-Org:mainfrom
proyectoauraorg:fix/242-omit-temperature-when-unset

Conversation

@proyectoauraorg

@proyectoauraorg proyectoauraorg commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

When "use custom temperature" is off, the OpenAI-Compatible provider still sent temperature: 0 (the fallback), so the model's server-side default never applied. Per the discussion on #242 (option A, which @edelauna preferred), this omits the temperature field in that case.

Behavior

temperature is now included only when either the user set a custom temperature or the model needs a specific default (e.g. deepseek-reasoner); otherwise it is omitted.

  • Preserves the supportsTemperature capability gate from fix(openai): omit temperature for models that don't support it (#215) #233 (still omitted when supportsTemperature === false).
  • Preserves model-required defaults (deepseek-reasonerDEEP_SEEK_DEFAULT_TEMPERATURE).
  • A deliberately-set 0 is distinguished from "unset" and is still sent.
  • Behavioral note: OpenAI-Compatible users who never set a temperature now get the model's server-side default instead of 0.

Scope

Targets the OpenAI-Compatible provider (the case reported in #242). The same ?? <default> pattern exists in the shared getModelParams and a few other providers (lite-llm, openai-native, lm-studio, vercel-ai-gateway, …); happy to converge them on this behavior in a follow-up — poe and moonshot already omit, so there is precedent.

Tests

api/providers/__tests__/openai.spec.ts: omitted by default, custom value sent, deliberate 0 sent, deepseek-reasoner default preserved, supportsTemperature === false still omitted. 53 pass.

Refs #242

Summary by CodeRabbit

  • Bug Fixes

    • Improved temperature parameter handling in API requests. Temperature is now conditionally omitted when unsupported by the model or when not explicitly provided, while respecting explicit user-set values including zero.
  • Tests

    • Updated test expectations to reflect refined temperature behavior across different AI service implementations.

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d2f00af4-1c73-477b-8e0e-03ae90641765

📥 Commits

Reviewing files that changed from the base of the PR and between 5bb3ac8 and f0a7f9d.

📒 Files selected for processing (2)
  • src/api/providers/__tests__/openai.spec.ts
  • src/api/providers/openai.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/api/providers/tests/openai.spec.ts
  • src/api/providers/openai.ts

📝 Walkthrough

Walkthrough

The PR modifies OpenAiHandler to conditionally omit the temperature parameter when creating chat completion requests, preventing a hardcoded 0 default from overriding server-side configurations. Tests validate that temperature is absent when unset but still transmitted when explicitly provided as 0.

Changes

Temperature Omission for OpenAI-Compatible Provider

Layer / File(s) Summary
Temperature parameter omission logic
src/api/providers/openai.ts
OpenAiHandler.createMessage now omits temperature from streaming requests when the model does not support it or when no custom temperature is provided, except for DeepSeek reasoner requests which fall back to DEEP_SEEK_DEFAULT_TEMPERATURE.
Test coverage for omission and explicit values
src/api/providers/__tests__/openai.spec.ts
Tests updated to assert that temperature is absent when no custom temperature is set, that explicit modelTemperature: 0 is transmitted as temperature: 0, and Azure AI Service expectations reflect the removed default temperature field.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly Related PRs

  • Zoo-Code-Org/Zoo-Code#233: Both PRs update OpenAiHandler.createMessage to conditionally omit temperature in the streaming request when supportsTemperature === false, with matching adjustments to openai.spec.ts expectations around that behavior.

Suggested Reviewers

  • taltas
  • navedmerchant
  • hannesrudolph
  • JamesRobert20

Poem

🐰 With whiskers twitching, we hop through the code,
Where temperatures once flowed but now take a rest,
When zero's not needed, we let it unload,
Allowing defaults to prove they know best! 🌡️✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: omitting temperature when no custom value is set in the OpenAI provider, directly matching the primary behavioral change described in the PR.
Description check ✅ Passed The description provides a clear summary, detailed behavior explanation, scope clarification, and test coverage, but does not include the required 'Related GitHub Issue' section or the pre-submission checklist from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/api/providers/__tests__/openai.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/api/providers/openai.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this, just had some nits around documentation and comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 i haven't been too strict about including changesets, can provide some rationale for providing this as part of this PR? I've kind of been thinking we'll update this as part of our release process, since it requires localization.

stream: true,
stream_options: { include_usage: true },
temperature: 0,
// #242 (option A): no custom temperature set → `temperature` is omitted.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok not to document the specific issue in code, it'll be handled in commit history.

@Mirrowel

Mirrowel commented May 25, 2026

Copy link
Copy Markdown

Was about to implement this, but someone got to it. Looking forward to this getting merged.

@proyectoauraorg proyectoauraorg force-pushed the fix/242-omit-temperature-when-unset branch from 5bb3ac8 to fd13906 Compare May 26, 2026 05:59
@proyectoauraorg

Copy link
Copy Markdown
Contributor Author

Conflicts resolved and branch rebased on latest main. CI is passing. Ready for re-review. 🙏

…rg#242)

When "use custom temperature" is off, the OpenAI-Compatible provider still sent temperature: 0 (the fallback), so the model's server-side default never applied. Per the discussion on Zoo-Code-Org#242 (option A), omit the temperature field in that case. Preserves the supportsTemperature gate (Zoo-Code-Org#233), model-required defaults (deepseek-reasoner), and a deliberately-set 0.
@drvaquera drvaquera force-pushed the fix/242-omit-temperature-when-unset branch from fd13906 to f0a7f9d Compare May 31, 2026 23:42
@proyectoauraorg

Copy link
Copy Markdown
Contributor Author

Thanks! Rebased onto main (resolved the openai.ts conflict — kept your updated example list incl. claude-opus-4-8) and addressed both nits:

  • Changeset: removed it, since it sounds like changesets are handled at release time given the localization step. Happy to re-add one with rationale if you'd prefer.
  • Issue refs in code: dropped the #242/option-A citations from the test names and the inline comment, leaving the descriptive text (the issue stays in the commit/PR for history).

tsc, eslint, and openai.spec.ts (53 tests) pass locally.

@proyectoauraorg

Copy link
Copy Markdown
Contributor Author

👋 Friendly ping — this PR has been open for 10 days.

Summary: Omits the deprecated temperature parameter when no custom value is set, fixing Claude Opus 4.7/4.8 failures.

  • ✅ CI green
  • ✅ Tests included
  • ✅ Small, focused change

Would appreciate a review when you have a moment 🙏

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - created issue to track some fixes that would be good to address which were revealed during review: #454

@edelauna edelauna enabled auto-merge June 2, 2026 22:21
@edelauna edelauna added this pull request to the merge queue Jun 2, 2026
Merged via the queue into Zoo-Code-Org:main with commit 9193941 Jun 2, 2026
10 of 11 checks passed
@edelauna edelauna mentioned this pull request Jun 5, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants